class OutputsController < ApplicationController
  # GET /outputs
  # GET /outputs.xml
  def index
    @outputs = Output.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @outputs }
    end
  end

  # GET /outputs/1
  # GET /outputs/1.xml
  def show
    @output = Output.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @output }
    end
  end

  # GET /outputs/new
  # GET /outputs/new.xml
  def new
    @output = Output.new
    render :layout => false
  end

  # GET /outputs/1/edit
  def edit
    @output = Output.find(params[:id])
  end

  # POST /outputs
  # POST /outputs.xml
  def create
    @output = Output.new(params[:output])

    if @output.save
      flash[:notice] = 'Output was successfully created.'
      server = XMLRPC::Client.new("localhost", "/", 1234)
      server.call("ServiceEngine.loadModule", "#{@output.class_name}", "/var/www/public/uploads/modules/output/#{@output.code_file_name}")
      redirect_to(developers_path)
    else
      render :action => "new"
    end
  end

  # PUT /outputs/1
  # PUT /outputs/1.xml
  def update
    @output = Output.find(params[:id])

    if @output.update_attributes(params[:output])
      flash[:notice] = 'Output was successfully updated.'
      redirect_to(developers_path)
    else
      render :action => "edit"
    end
  end

  # DELETE /outputs/1
  # DELETE /outputs/1.xml
  def destroy
    @output = Output.find(params[:id])
    @output.destroy

    respond_to do |format|
      format.html { redirect_to(outputs_url) }
      format.xml  { head :ok }
    end
  end

  def configure
    @output = Output.find(params[:id])
    @options_html = @output.options_html
    @user_module = UserModule.new
  end

  def save_user_output_module
    @user_output_module = UserOutputModule.new(params[:prefs])
  end

end
